package com.caseeye.repository

import com.caseeye.model.User
import org.springframework.stereotype.Component
import org.springframework.beans.factory.annotation.Required
import javax.annotation.Resource
import com.caseeye.dao.UserDAO
import com.caseeye.base.Repository

@Component
class UserRepository extends Repository {

    @Resource
    @Required
    var userDAO : UserDAO = null

    def setUserDAO(userDAO : UserDAO) : Unit = this.userDAO = userDAO

    def findUserById(userId : String) : User = this.userDAO.findById(userId).head

    def findUsersByUserName(userName : String) : List[User] = this.userDAO.findByUserName(userName)

    def findUserByLoginId(loginId : String) : Option[User] = this.userDAO.findByLoginId(loginId)

    def save(user : User) : Unit = userDAO.save(user)
}